package com.aaa.controller;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.MyReturn;
import com.aaa.entity.QuestionSas;
import com.aaa.entity.TblQuestionSds;
import com.aaa.service.TblQuestionSdsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 问题表(TblQuestionSds)表控制层
 *
 * @author makejava
 * @since 2022-07-15 20:48:06
 */
@RestController
@RequestMapping("tblQuestionSds")
public class TblQuestionSdsController extends BaseController{
    MyReturn myReturn = new MyReturn();
    /**
     * 服务对象
     */
    @Resource
    private TblQuestionSdsService tblQuestionSdsService;

    @RequestMapping("toShowQuestionSds.do")
    public ModelAndView toShowQuestionSds(ModelAndView modelAndView) {
        modelAndView.setViewName("showQuestionSds");
        return modelAndView;
    }
    /**
     * 分页查询
     *
     * @param tblQuestionSds 筛选条件
     * @param page    分页对象
     * @return 查询结果
     */
    @GetMapping("allQuestionSds.do")
    public ResponseEntity<Page<TblQuestionSds>> queryByPage(TblQuestionSds tblQuestionSds, Integer page, Integer limit) {
        PageRequest pageRequest = PageRequest.of(page - 1, limit);
        return ResponseEntity.ok(this.tblQuestionSdsService.queryByPage(tblQuestionSds, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TblQuestionSds> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tblQuestionSdsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tblQuestionSds 实体
     * @return 新增结果
     */
    @PostMapping("insertSds.do")
    @InsertAnn
    public MyReturn add(TblQuestionSds tblQuestionSds) {
        boolean insert = this.tblQuestionSdsService.insert(tblQuestionSds);
        if (insert) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * 编辑数据
     *
     * @param tblQuestionSds 实体
     * @return 编辑结果
     */
    @RequestMapping("updateSds.do")
    @UpdateAnn
    public MyReturn edit(TblQuestionSds tblQuestionSds) {
        boolean update = this.tblQuestionSdsService.update(tblQuestionSds);
        if (update) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * 删除数据
     *
     * @param idList 主键
     * @return 删除是否成功
     */
    @RequestMapping("deleteSds.do")
    public MyReturn deleteById(String idList) {
        boolean b = this.tblQuestionSdsService.deleteById(idList);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 题目唯一性校验
     * @create time: 2022/7/14 17:00
     * @param "QuestionFpa"
     * @return MyReturn
     */
    @GetMapping("repetitionName.do")
    public MyReturn repetitionName(TblQuestionSds TblQuestionSds){
        boolean b = this.tblQuestionSdsService.repetitionName(TblQuestionSds);
        if (b){
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

}

